﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Library
{
    public class Book
    {
        public string Title { get; }
        public string Author { get; }
        public int StockNum { get; set; }
        public int BorrowedQuantity { get; private set; }

        public Book(string title, string author, int stockNum)
        {
            Title = title;
            Author = author;
            StockNum = stockNum;
            BorrowedQuantity = 0;
        }

        public int AvailableQuantity()
        {
            return StockNum - BorrowedQuantity;
        }

        public bool Borrow(int quantity)
        {
            if (quantity > AvailableQuantity())
            {
                Console.WriteLine("超出剩余库存数!");
                return false;
            }
            BorrowedQuantity += quantity;
            Console.WriteLine($"已借阅书籍: 《{Title}》 {quantity}本 ");
            return true;
        }

        public bool Return(int quantity)
        {
            if (quantity > BorrowedQuantity)
            {
                Console.WriteLine("超出已借阅数!");
                return false;
            }
            BorrowedQuantity -= quantity;
            Console.WriteLine($"已归还书籍: 《{Title}》 {quantity}本 ");
            return true;
        }

        public override string ToString()
        {
            return $"书名:《{Title}》\t作者: {Author}\t可借阅数: {AvailableQuantity()}";
        }
    }
}
